/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import com.alibaba.druid.pool.DruidDataSource;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * <p>Project: jdbc202202 - DruidDemo
 * <p>Powered by webrx On 2022-08-22 17:01:08
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class DruidDemo {
    public static void main(String[] args) throws SQLException {
        DruidDataSource ds = new DruidDataSource();
        ds.setDriverClassName("com.mysql.cj.jdbc.Driver");
        ds.setUrl("jdbc:mysql://localhost:3306/db?serverTimezone=PRC&useUnicode=true&characterEncoding=utf8");
        ds.setUsername("root");
        ds.setPassword("");

        //初始化时建立物理连接的个数 ，默认值为0
        ds.setInitialSize(10);
        //最大连接池数量，默认值为8
        ds.setMaxActive(50);

        ds.setMinIdle(15);

        Connection conn1 = ds.getConnection();
        System.out.println(conn1);
        Connection conn2 = ds.getConnection();
        System.out.println(conn2);
        System.out.println(conn1 == conn2);
    }
}
